{% extends "profile/base.html" %}

{% block title %}编辑个人资料 - 用户资料管理系统{% endblock %}

{% block extra_css %}
<style>
    .profile-page {
        background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        min-height: calc(100vh - 200px);
        padding: 2rem 0;
    }
    
    .profile-avatar {
        width: 150px;
        height: 150px;
        border-radius: 50%;
        object-fit: cover;
        border: 4px solid #fff;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
    
    .profile-sidebar {
        background: #fff;
        border-radius: 15px;
        padding: 2rem;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        margin-bottom: 2rem;
        transition: transform 0.3s ease;
    }
    
    .profile-sidebar:hover {
        transform: translateY(-5px);
    }
    
    .card {
        border: none;
        border-radius: 15px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        overflow: hidden;
        transition: transform 0.3s ease;
    }
    
    .card:hover {
        transform: translateY(-5px);
    }
    
    .card-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        padding: 1.5rem;
    }
    
    .form-control, .form-select {
        border-radius: 10px;
        border: 1px solid #e0e0e0;
        padding: 0.75rem;
        transition: all 0.3s ease;
    }
    
    .form-control:focus, .form-select:focus {
        border-color: #667eea;
        box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
    }
    
    .btn-primary {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border: none;
        border-radius: 10px;
        padding: 0.75rem 1.5rem;
        font-weight: 600;
        transition: all 0.3s ease;
    }
    
    .btn-primary:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
    }
    
    .avatar-preview {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        object-fit: cover;
        border: 3px solid #e0e0e0;
    }
    
    .fade-in {
        animation: fadeIn 0.5s ease-in;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(20px); }
        to { opacity: 1; transform: translateY(0); }
    }
</style>
{% endblock %}

{% block content %}
<div class="profile-page">
    <div class="container">
        <div class="row mb-4">
            <div class="col-12">
                <div class="text-center fade-in">
                    <h1 class="display-4 fw-bold text-white mb-3">编辑个人资料</h1>
                    <p class="lead text-white-50">更新您的个人信息和偏好设置</p>
                </div>
            </div>
        </div>
        
        <div class="row fade-in">
            <div class="col-md-4">
                <div class="profile-sidebar">
                    <div class="mb-3">
                        {% if user.avatar %}
                        <img src="{{ url_for('profile.uploaded_file', filename=user.avatar) }}" class="profile-avatar" alt="用户头像">
                        {% else %}
                        <div class="profile-avatar d-flex align-items-center justify-content-center bg-light text-secondary">
                            <i class="bi bi-person fs-1"></i>
                        </div>
                        {% endif %}
                    </div>
                    <h5>{{ user.nickname or user.username }}</h5>
                    <p class="text-muted">{{ user.email }}</p>
                </div>
            </div>
            
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-edit me-2"></i>编辑个人资料</h5>
                    </div>
                    <div class="card-body">
                        <form method="POST" enctype="multipart/form-data" class="ajax-form">
                            {{ form.hidden_tag() }}
                            
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    {{ form.username.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-user"></i></span>
                                        {{ form.username(class="form-control") }}
                                    </div>
                                    {% if form.username.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.username.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                                
                                <div class="col-md-6 mb-3">
                                    {{ form.email.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-envelope"></i></span>
                                        {{ form.email(class="form-control") }}
                                    </div>
                                    {% if form.email.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.email.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    {{ form.nickname.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-id-badge"></i></span>
                                        {{ form.nickname(class="form-control") }}
                                    </div>
                                    {% if form.nickname.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.nickname.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                                
                                <div class="col-md-6 mb-3">
                                    {{ form.age.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-birthday-cake"></i></span>
                                        {{ form.age(class="form-control") }}
                                    </div>
                                    {% if form.age.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.age.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    {{ form.gender.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-venus-mars"></i></span>
                                        {{ form.gender(class="form-select") }}
                                    </div>
                                    {% if form.gender.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.gender.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                                
                                <div class="col-md-6 mb-3">
                                    {{ form.phone.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-phone"></i></span>
                                        {{ form.phone(class="form-control") }}
                                    </div>
                                    {% if form.phone.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.phone.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    {{ form.birth_date.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-calendar"></i></span>
                                        {{ form.birth_date(class="form-control") }}
                                    </div>
                                    {% if form.birth_date.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.birth_date.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                                
                                <div class="col-md-6 mb-3">
                                    {{ form.address.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-map-marker-alt"></i></span>
                                        {{ form.address(class="form-control") }}
                                    </div>
                                    {% if form.address.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.address.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    {{ form.interests.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-heart"></i></span>
                                        {{ form.interests(class="form-control") }}
                                    </div>
                                    {% if form.interests.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.interests.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                                
                                <div class="col-md-6 mb-3">
                                    {{ form.website.label(class="form-label") }}
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="fas fa-globe"></i></span>
                                        {{ form.website(class="form-control") }}
                                    </div>
                                    {% if form.website.errors %}
                                        <div class="text-danger small mt-1">
                                            {% for error in form.website.errors %}
                                                {{ error }}
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                            </div>
                            
                            <div class="mb-3">
                                {{ form.bio.label(class="form-label") }}
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fas fa-comment"></i></span>
                                    {{ form.bio(class="form-control", rows="4") }}
                                </div>
                                {% if form.bio.errors %}
                                    <div class="text-danger small mt-1">
                                        {% for error in form.bio.errors %}
                                            {{ error }}
                                        {% endfor %}
                                    </div>
                                {% endif %}
                            </div>
                            
                            <div class="mb-3">
                                {{ form.avatar.label(class="form-label") }}
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fas fa-image"></i></span>
                                    {{ form.avatar(class="form-control", accept="image/*") }}
                                </div>
                                {% if form.avatar.errors %}
                                    <div class="text-danger small mt-1">
                                        {% for error in form.avatar.errors %}
                                            {{ error }}
                                        {% endfor %}
                                    </div>
                                {% endif %}
                                <div class="form-text">支持jpg、jpeg、png、gif、webp格式，最大5MB</div>
                                
                                <div class="mt-2">
                                    <label class="form-label">头像预览</label>
                                    <div>
                                        <img id="avatar-preview" 
                                             src="{% if user.avatar %}{{ url_for('profile.uploaded_file', filename=user.avatar) }}{% else %}https://via.placeholder.com/150x150{% endif %}" 
                                             class="avatar-preview" 
                                             alt="头像预览">
                                    </div>
                                </div>
                            </div>
                            
                            <div class="mb-3 form-check">
                                {{ form.is_public(class="form-check-input") }}
                                {{ form.is_public.label(class="form-check-label") }}
                                {% if form.is_public.errors %}
                                    <div class="text-danger small mt-1">
                                        {% for error in form.is_public.errors %}
                                            {{ error }}
                                        {% endfor %}
                                    </div>
                                {% endif %}
                                <div class="form-text">如果勾选，其他用户可以查看您的个人资料</div>
                            </div>
                            
                            <div class="d-grid">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fas fa-check-circle me-2"></i>保存更改
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 初始化动画
        const elements = document.querySelectorAll('.fade-in');
        elements.forEach((el, index) => {
            setTimeout(() => {
                el.style.opacity = '1';
                el.style.transform = 'translateY(0)';
            }, index * 100);
        });
        
        // 头像预览功能
        const avatarInput = document.querySelector('input[name="avatar"]');
        const avatarPreview = document.getElementById('avatar-preview');
        
        if (avatarInput && avatarPreview) {
            avatarInput.addEventListener('change', function() {
                const file = this.files[0];
                if (file) {
                    const reader = new FileReader();
                    reader.onload = function(e) {
                        avatarPreview.src = e.target.result;
                    };
                    reader.readAsDataURL(file);
                }
            });
        }
    });
</script>
{% endblock %}